package com.gientech.demoprovider.controller;

import com.gientech.demoprovider.entity.Student;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/provider")
public class DemoController {

    @GetMapping("/test")
    public Student test(){
        Student a = new Student();
        a.setAge(18);
        a.setName("Wang");
        a.setSex("male");

        return a;
    }

    @GetMapping("/test/{id}")
    public String testpath(@PathVariable("id") String id ){
        System.out.println("id : " + id);

        return id;
    }

    @GetMapping("/testone")
    public String test1(@RequestParam(value = "username") String username, @RequestParam(value = "password") String password){
        System.out.println("username : " + username);
        System.out.println("password : " + password);

        if("root".equalsIgnoreCase(username)){
            return "succ";
        }

        return "error";
    }

    @PostMapping("/testpost")
    public String testpost(@RequestBody String username){
        System.out.println("username : " + username);

        return "error";
    }

    @PostMapping("/testpostone")
    public String testpostone(@RequestBody Student stu){
        System.out.println(stu);

        return "error";
    }

    @PostMapping("/testpostbody")
    public String testpostBody(@RequestBody Student stu){
        System.out.println("name : " + stu.getName());
        System.out.println("set : " + stu.getSex());
        System.out.println("age : " + stu.getAge());

        return "error";
    }

    @DeleteMapping("/testdelete/{id}")
    public String testdelete(@PathVariable("id") String id){
        System.out.println("id : " + id);

        return id;
    }
}

